package roy.abc.study.WebServices.JavaWSUpAndRunning.ch02;

import java.util.List;

import javax.xml.ws.Holder;

import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.AWSECommerceService;
import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.AWSECommerceServicePortType;
import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.Item;
import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.ItemSearch;
import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.ItemSearchRequest;
import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.Items;
import roy.abc.study.WebServices.JavaWSUpAndRunning.ch02.awsClient.OperationRequest;

public class AmazonClientW {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final String access_key = "AKIAIM2LT5TSFA4UNTAA";
		
		AWSECommerceService service = new AWSECommerceService();
		AWSECommerceServicePortType port = service.getAWSECommerceServicePort();
		
		ItemSearchRequest request = new ItemSearchRequest();
		request.setSearchIndex("Books");
		request.setKeywords("quantum gravity");
		
		ItemSearch search = new ItemSearch();
		search.getRequest().add(request);
		search.setAWSAccessKeyId(access_key);
		
		Holder<OperationRequest> operationRequest = null;
		Holder<List<Items>> items = new Holder<List<Items>>();
		
		port.itemSearch(search.getMarketplaceDomain(),
				search.getAWSAccessKeyId(), 
				search.getSubscriptionId(),
				search.getAssociateTag(), 
				search.getXMLEscaping(),
				search.getValidate(),
				search.getShared(),
				search.getRequest(), 
				operationRequest, 
				items);
		
		Items retval = items.value.get(0);
		List<Item> item_list = retval.getItem();
		for(Item item : item_list){
			System.out.println(item.getItemAttributes().getTitle());
		}
	}
}
